package com.lft01.thread;

/**
 * Function: 		ADD FUNCTION.
 * Reason:   		ADD REASON.
 * Date             2020/6/6 13:02
 * <p>
 * Class Name:      NumPrintTest
 * Package Name:    com.lft.thread
 *
 * @author Laifengting
 * @version 1.0.0
 * @since JDK 8
 */
public class NumPrintTest {
	public static int num = 0;
	
	public synchronized void print0() {
		while (num == 0) {
			try {
				this.wait();
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
		}
		num--;
		System.out.println(Thread.currentThread().getName() + " 打印 " + num);
		this.notifyAll();
		
	}
	
	public synchronized void print1() {
		while (num == 1) {
			try {
				this.wait();
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
		}
		num++;
		System.out.println(Thread.currentThread().getName() + " 打印 " + num);
		this.notifyAll();
	}
}
